package com.sinooceangroup.capital.nacosconfig.controller;

import com.sinooceangroup.capital.nacosconfig.config.UserConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * config api
 *
 * @author: Leo.Wang, adwyxx@qq.com
 * @date: 2020/7/22 10:10
 */
@RestController
@RefreshScope
public class ConfigController {

    @Autowired
    UserConfig userConfig;

    /***
     * 这里使用了远程配置的内容，所以在Controller上要添加 @RefreshScope 注解
     */
    @Value("${config.value}")
    String value;

    @GetMapping("/config")
    public UserConfig getConfig(){
        return userConfig;
    }
    @GetMapping("/config-value")
    public String getValueConfig(){
        return value;
    }
}
